const regs = {
    email:/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/,
    number: /^([0]|[1-9][0-9]*)$/,
    password: /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z~!@#$%^&*_]{8,18}$/,
    shareCode: /^[A-Za-z0-9]+$/
}
const verify = (rule,value,reg,callback)=>{
    if(value){
        if(reg.test(value)){

            return callback();
        }else{
            return callback(new Error(rule.message));
        }
    }else {
        return callback();
    }
}

export default {
    email:(rule,value,callback)=>{
        return verify(rule,value,regs.email,callback)
    },
    number:(rule,value,callback)=>{
        return verify(rule,value,regs.number,callback)
    },
    password:(rule,value,callback)=>{
        return verify(rule,value,regs.password,callback)
    },
    shareCode:(rule,value,callback)=>{
        return verify(rule,value,regs.shareCode,callback)
    }
}